﻿namespace UFIDA.U9.Cust.SH.SHFastShipBP
{
	using System;
	using System.Collections.Generic;
	using System.Text; 
	using UFSoft.UBF.AopFrame;	
	using UFSoft.UBF.Util.Context;
    using UFIDA.U9.CBO.SCM.Customer;
    using UFIDA.U9.CBO.SCM.Warehouse;
    using UFIDA.U9.Base;

	/// <summary>
	/// GetDefaultWH partial 
	/// </summary>	
	public partial class GetDefaultWH 
	{	
		internal BaseStrategy Select()
		{
			return new GetDefaultWHImpementStrategy();	
		}		
	}
	
	#region  implement strategy	
	/// <summary>
	/// Impement Implement
	/// 
	/// </summary>	
	internal partial class GetDefaultWHImpementStrategy : BaseStrategy
	{
		public GetDefaultWHImpementStrategy() { }

		public override object Do(object obj)
		{						
			GetDefaultWH bpObj = (GetDefaultWH)obj;
			
			//get business operation context is as follows
			//IContext context = ContextManager.Context	
			
			//auto generating code end,underside is user custom code
			//and if you Implement replace this Exception Code...
			//throw new NotImplementedException();

            if (bpObj.CustID <= 0) return null;
            Customer cu = Customer.Finder.FindByID(bpObj.CustID);
            if (cu == null) throw new Exception("查找客户失败！");

            if(string.IsNullOrEmpty( cu.DescFlexField.PubDescSeg23)) return null;

            Warehouse wh = Warehouse.Finder.Find(" Code='" + cu.DescFlexField.PubDescSeg23+"'");
            if (wh == null) throw new Exception("依据客户查找仓库失败，仓库编码：" + cu.DescFlexField.PubDescSeg23);

            EntityDTO dto = new EntityDTO();
            dto.ID = wh.ID;
            dto.Code=wh.Code;
            dto.Name=wh.Name;

            return dto;
		}		
	}

	#endregion
	
	
}